const nodemailer = require('nodemailer');
const fs = require('fs')
const path = require('path')
const { transFormHtmlImgSrcToBase64 } = require('./utils/transFormHtmlImgSrcToBase64.js')

const user = 'jdzhang@fiberhome.com'
const pass = ''
const to = 'jdzhang@fiberhome.com'


// 设置发送服务器地址及账号信息
let transporter = nodemailer.createTransport({
    host: 'smtp.fiberhome.com',
    port: 465,
    secure: true,
    auth: {
        user,
        pass
    }
});
// 读取html文件
const emailTextPath = './static/index.html'
const htmlSrc = fs.readFileSync(emailTextPath, {
    encoding: 'utf-8'
})
// 解决html文件中img标签的src问题
const html = transFormHtmlImgSrcToBase64(htmlSrc, path.dirname(emailTextPath))
// 设置邮件信息
let mailOptions = {
    from: user,
    to,
    subject: '快来加班',
    html
};
// 发送邮件
transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
        console.log(error);
    } else {
        console.log('Email sent: ' + info.response);
    }
});

